package com.init.engineering.service.impl;

import com.init.engineering.dao.StageDao;
import com.init.engineering.pages.PageResult;
import com.init.engineering.pages.QueryPageBean;
import com.init.engineering.pojo.Stage;
import com.init.engineering.service.StageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StageServiceImpl implements StageService {
    @Autowired(required = false)
    private StageDao stageDao;

    @Override
    public List<Stage> findStages() {
        List<Stage> stages = stageDao.findStages();
        return stages;
    }

    @Override
    public PageResult findStagesByPage(QueryPageBean queryPageBean) {
        Integer begin = (queryPageBean.getCurrentPage() - 1) * queryPageBean.getPageSize();
        queryPageBean.setCurrentPage(begin);
        //查询当前页的数据集合
        List<Stage> stages = stageDao.findStagesByPage(queryPageBean);
        //获取分页查询的条件
        String queryString = queryPageBean.getQueryString();
        //获取分页查询按条件查询的总条数
        long totalCount = stageDao.selectTotalCount(queryString);

        //将数据封装到PageResult内
        PageResult pageResult = new PageResult();
        pageResult.setTotal(totalCount);
        pageResult.setRows(stages);
        return pageResult;
    }

    @Override
    public int saveStage(Stage stage) {
        int rows = stageDao.saveStage(stage);
        return rows;
    }

    @Override
    public int deleteStage(String sid) {
        int rows = stageDao.updateStatusStage(sid);
        return rows;
    }

    @Override
    public Stage findStageBySid(String sid) {
        Stage stage = stageDao.findStageBySid(sid);
        return stage;
    }

    @Override
    public int updateStage(Stage stage) {
        int rows = stageDao.updateStage(stage);
        return rows;
    }

    @Override
    public List<Stage> findStagesByPid(int pid) {
        List<Stage> stages = stageDao.findStageByPid(pid);
        return stages;
    }
}
